home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / 92052tar.gz / 920528.tar / udpdump.c < prev    next >
C/C++ Source or Header  |  1991-05-10  |  1KB  |  61 lines

  1. /* @(#) $Header: udpdump.c,v 1.5 91/05/09 07:39:11 deyke Exp $ */
  2.  
  3. /* UDP packet tracing
  4.  * Copyright 1991 Phil Karn, KA9Q
  5.  */
  6. #include <stdio.h>
  7. #include "global.h"
  8. #include "mbuf.h"
  9. #include "netuser.h"
  10. #include "internet.h"
  11. #include "udp.h"
  12. #include "ip.h"
  13. #include "socket.h"
  14. #include "trace.h"
  15.  
  16. /* Dump a UDP header */
  17. void
  18. udp_dump(fp,bpp,source,dest,check)
  19. FILE *fp;
  20. struct mbuf **bpp;
  21. int32 source,dest;
  22. int check;              /* If 0, bypass checksum verify */
  23. {
  24.     struct udp udp;
  25.     struct pseudo_header ph;
  26.     int16 csum;
  27.  
  28.     if(bpp == NULLBUFP || *bpp == NULLBUF)
  29.         return;
  30.  
  31.     fprintf(fp,"UDP:");
  32.  
  33.     /* Compute checksum */
  34.     ph.source = source;
  35.     ph.dest = dest;
  36.     ph.protocol = UDP_PTCL;
  37.     ph.length = len_p(*bpp);
  38.     if((csum = cksum(&ph,*bpp,ph.length)) == 0)
  39.         check = 0;      /* No checksum error */
  40.  
  41.     ntohudp(&udp,bpp);
  42.  
  43.     fprintf(fp," len %u",udp.length);
  44.     fprintf(fp," %u->%u",udp.source,udp.dest);
  45.     if(udp.length > UDPHDR)
  46.         fprintf(fp," Data %u",udp.length - UDPHDR);
  47.     if(udp.checksum == 0)
  48.         check = 0;
  49.     if(check)
  50.         fprintf(fp," CHECKSUM ERROR (%u)",csum);
  51.  
  52.     putc('\n',fp);
  53.  
  54.     switch(udp.dest){
  55.     case IPPORT_RIP:
  56.         rip_dump(fp,bpp);
  57.     }
  58.  
  59. }
  60.  
  61.